package com.example.plan.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.plan.common.PageRequest;
import com.example.plan.common.result.Result;
import com.example.plan.model.dto.userAddress.UserAddressDTO;
import com.example.plan.model.vo.UserAddressVO;
import com.example.plan.service.UserAddressService;
import com.example.plan.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.Getter;
import lombok.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

@Data
@Api(tags = "地址模块")
@RestController
@RequestMapping("userAddress")

public class UserAddressController {

    private final UserAddressService userAddressService;

    @PostMapping("/saveUserAddress")
    @ApiOperation(value = "新增用户地址")
    public Result<Void> saveUserAddress(@RequestBody @Validated UserAddressDTO dto) {
        return userAddressService.saveUserAddress(dto);
    }

    @GetMapping("/deleteUserAddress/{addressId}")
    @ApiOperation(value = "删除用户地址")
    public Result<Void> deleteUserAddress(@PathVariable @NotNull Long addressId) {
        return userAddressService.deleteUserAddress(addressId);
    }

    @PostMapping("/updateUserAddress")
    @ApiOperation(value = "修改用户地址")
    public Result<Void> updateUserAddress(@RequestBody @Validated UserAddressDTO dto) {
        return userAddressService.updateUserAddress(dto);
    }

    @PostMapping("/pageUserAddress")
    @ApiOperation(value = "分页查询用户地址")
    public Result<IPage<UserAddressVO>> pageUserAddress(@RequestBody @Validated PageRequest pageRequest) {
        return userAddressService.selectUserAddress(pageRequest);
    }


}